/**
 * 
 */
package mdb.com.vn.web.beans;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;

import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;

import mdb.com.vn.model.Casa;
import mdb.com.vn.model.FixedDepositCasa;
import mdb.com.vn.model.FixedDeposits;
import mdb.com.vn.model.ScratchCard;
import mdb.com.vn.services.MDBServices;
import mdb.com.vn.utils.DateUtils;
import mdb.com.vn.utils.NumberUtils;
import mdb.com.vn.web.utils.FacesContextUtils;

/**
 * @author tu.dod
 * 
 */
@ManagedBean(name = "luckyDrawBeans")
@ViewScoped
public class LuckyDrawBeans implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String savingBookNo;
	private int number00k;
	private int number20k;
	private int number50k;
	private int number100k;
	private int number200k;
	private int number500k;

	private String detail20k;
	private String detail50k;
	private String detail100k;
	private String detail200k;
	private String detail500k;

	private String customerName;
	private String customerId;
	private String branchCode;
	private String programJoined;

	private int luckyDraw;
	private int sc_Card;
	private int tshirtGift;
	private int trayGift;
	private int voucherGift;
	private int voucherGiftMore;

	private int bgiftReceived;
	private int tgiftReceived;

	private StreamedContent file;

	private FixedDeposits fixedDeposits;
	private FixedDepositCasa fixedDepositCasa;
	private Casa casa;

	private boolean btnVisible;
	private boolean btnSaveVisible;
	private int totalScradAvailable;
	private double totalAmountAvailable;

	private int nav_flag = 0;

	@ManagedProperty("#{mdbServices}")
	private MDBServices mdbServices;

	@PostConstruct
	public void init() {
		savingBookNo = "";

	}

	public void setMdbServices(MDBServices mdbServices) {
		this.mdbServices = mdbServices;
	}

	public void search2RePrint() {
		fixedDeposits = mdbServices.findFixedDepositsByCode(savingBookNo);
		if (fixedDeposits != null) {
			nav_flag = 1;
			int ldrAvailble = mdbServices.getSCardFDAvailableException(
					fixedDeposits.getCustomerId(),
					fixedDeposits.getSavingbookNo())
					+ mdbServices.getSCardCSAvailable(fixedDeposits
							.getCustomerId())
					+ mdbServices.getSCardFDCSAvailable(fixedDeposits
							.getCustomerId());
			setTotalScradAvailable(ldrAvailble);
			if (fixedDeposits.getCustomerType() == 1
					&& fixedDeposits.getInterestRate() != 7.5) {
				int tocalculatebag = fixedDeposits.getScCard()
						+ getTotalScradAvailable();
				fixedDeposits.setBagGift(tocalculatebag / 5);
				fixedDeposits.setTrayGift(tocalculatebag / 10);
			}

			if (fixedDeposits.getCustomerType() == 2
					&& fixedDeposits.getInterestRate() != 7.5) {
				int tocalculatebag = fixedDeposits.getScCard()
						+ getTotalScradAvailable();
				fixedDeposits.setVoucherGiftMore(tocalculatebag / 30);
			}
			if (fixedDeposits.getCustomerType() == 2) {
				setTotalAmountAvailable(mdbServices
						.getAmountCorpAvailableException(fixedDeposits.getCustomerId(),fixedDeposits.getSavingbookNo()));
			}

			// ///////////////////////////////////////
			if (fixedDeposits.getCustomerType() == 1
					&& fixedDeposits.getInterestRate() == 7.5) {
				fixedDeposits.setBagGift(getTotalScradAvailable() / 5);
				fixedDeposits.setTrayGift(getTotalScradAvailable() / 10);
				fixedDeposits.setScCardNotGet(0);
			}
			if (fixedDeposits.getCustomerType() == 2
					&& fixedDeposits.getInterestRate() == 7.5) {
				fixedDeposits.setVoucherGiftMore(getTotalScradAvailable() / 30);
				fixedDeposits.setScCardNotGet(0);
			}
			// ///////////////////////////////////////
		} else {
			casa = mdbServices.findCasaByCode(savingBookNo);
			if (casa != null) {
				nav_flag = 2;
				int ldrAvailbleCS = mdbServices.getSCardFDAvailable(casa
						.getCustomerId())
						+ mdbServices.getSCardCSAvailableException(
								casa.getCustomerId(), casa.getAccountLocked())
						+ mdbServices.getSCardFDCSAvailable(casa
								.getCustomerId());
				setTotalScradAvailable(ldrAvailbleCS);
				if (casa.getCustomerType() == 1) {
					int tocalculatebag = casa.getScCard()
							+ getTotalScradAvailable();
					casa.setBagGift(tocalculatebag / 5);
					casa.setTrayGift(tocalculatebag / 10);
				}

			} else {
				fixedDepositCasa = mdbServices.findFixedDepositCasaByCode(
						savingBookNo, savingBookNo);
				if (fixedDepositCasa != null) {
					nav_flag = 3;
					int ldrAvailbleFDCS = mdbServices
							.getSCardFDAvailable(fixedDepositCasa
									.getCustomerId())
							+ mdbServices.getSCardCSAvailable(fixedDepositCasa
									.getCustomerId())
							+ mdbServices.getSCardFDCSAvailableException(
									fixedDepositCasa.getCustomerId(),
									fixedDepositCasa.getSavingbookNo());
					setTotalScradAvailable(ldrAvailbleFDCS);
					if (fixedDepositCasa.getCustomerType() == 1) {
						int tocalculatebag = fixedDepositCasa.getScCard()
								+ getTotalScradAvailable();
						fixedDepositCasa.setBagGift(tocalculatebag / 5);
						fixedDepositCasa.setTrayGift(tocalculatebag / 10);
					}
				} else {
					nav_flag = 0;
				}
			}
		}
		switch (nav_flag) {
		case 0:
			setSavingBookNo("");
			setCustomerId("");
			setCustomerName("");
			setBranchCode("");
			setLuckyDraw(0);
			setSc_Card(0);
			setNumber00k(0);
			setProgramJoined("");
			setNumber20k(0);
			setDetail20k("");
			setTshirtGift(0);
			setTrayGift(0);
			setBgiftReceived(0);
			setTgiftReceived(0);
			setBtnSaveVisible(false);
			setBtnVisible(false);
			break;
		case 1:
			setCustomerId(fixedDeposits.getCustomerId());
			setCustomerName(fixedDeposits.getCustomerName());
			setBranchCode(fixedDeposits.getBranchCode());
			setLuckyDraw(fixedDeposits.getLuckyDraw());
			setSc_Card(fixedDeposits.getScCard());
			setNumber00k(fixedDeposits.getCheckGetThankSC());
			setProgramJoined("TIỀN GỬI TIẾT KIỆM CÓ KỲ HẠN");
			List<ScratchCard> scratchCards = mdbServices
					.getScratchCardByRef(fixedDeposits.getSavingbookNo());
			for (ScratchCard scratchCard : scratchCards) {
				double deno = scratchCard.getScDenomination();
				int quality = scratchCard.getQuantity();
				if (deno == NumberUtils.VND20000) {
					setNumber20k(quality);
					setDetail20k(scratchCard.getScDesription());
				}
				if (deno == NumberUtils.VND50000) {
					setNumber50k(quality);
					setDetail50k(scratchCard.getScDesription());
				}
				if (deno == NumberUtils.VND100000) {
					setNumber100k(quality);
					setDetail100k(scratchCard.getScDesription());
				}
				if (deno == NumberUtils.VND200000) {
					setNumber200k(quality);
					setDetail200k(scratchCard.getScDesription());
				}
				if (deno == NumberUtils.VND500000) {
					setNumber500k(quality);
					setDetail500k(scratchCard.getScDesription());
				}
			}
			if (fixedDeposits.getCustomerType() == 1) {
				setTshirtGift(fixedDeposits.getBagGift());
				setTrayGift(fixedDeposits.getTrayGift());
				setBgiftReceived(fixedDeposits.getBgiftReceived());
				setTgiftReceived(fixedDeposits.getTgiftReceived());

			} else {
				setVoucherGiftMore(fixedDeposits.getVoucherGiftMore());
				setVoucherGift(fixedDeposits.getVoucherGift());
			}
			setBtnSaveVisible(true);

			break;
		case 2:
			setCustomerId(casa.getCustomerId());
			setCustomerName(casa.getCustomerName());
			setBranchCode(casa.getBranchCode());
			setLuckyDraw(casa.getLuckyDraw());
			setSc_Card(casa.getScCard());
			setNumber00k(casa.getCheckGetThankSC());
			setProgramJoined("TIỀN GỬI TIẾT KIỆM KHÔNG KỲ HẠN");
			List<ScratchCard> scratchCardsCS = mdbServices
					.getScratchCardByRef(casa.getAccountLocked());
			for (ScratchCard scratchCard : scratchCardsCS) {
				double deno = scratchCard.getScDenomination();
				int quality = scratchCard.getQuantity();
				if (deno == NumberUtils.VND20000) {
					setNumber20k(quality);
					setDetail20k(scratchCard.getScDesription());
				}
				if (deno == NumberUtils.VND50000) {
					setNumber50k(quality);
					setDetail50k(scratchCard.getScDesription());
				}
				if (deno == NumberUtils.VND100000) {
					setNumber100k(quality);
					setDetail100k(scratchCard.getScDesription());
				}
				if (deno == NumberUtils.VND200000) {
					setNumber200k(quality);
					setDetail200k(scratchCard.getScDesription());
				}
				if (deno == NumberUtils.VND500000) {
					setNumber500k(quality);
					setDetail500k(scratchCard.getScDesription());
				}
			}
			if (casa.getCustomerType() == 1) {
				setTshirtGift(casa.getBagGift());
				setTrayGift(casa.getTrayGift());
				setBgiftReceived(casa.getBgiftReceived());
				setTgiftReceived(casa.getTgiftReceived());

			}
			setBtnSaveVisible(true);
			break;
		case 3:
			setCustomerId(fixedDepositCasa.getCustomerId());
			setCustomerName(fixedDepositCasa.getCustomerName());
			setBranchCode(fixedDepositCasa.getBranchCode());
			setLuckyDraw(fixedDepositCasa.getLuckyDraw());
			setSc_Card(fixedDepositCasa.getScCard());
			setNumber00k(fixedDepositCasa.getCheckGetThankSC());
			setProgramJoined("TIỀN GỬI TIẾT KIỆM KẾT HỢP");
			List<ScratchCard> scratchCardsFDCS = mdbServices
					.getScratchCardByRef(fixedDepositCasa.getSavingbookNo());
			for (ScratchCard scratchCard : scratchCardsFDCS) {
				double deno = scratchCard.getScDenomination();
				int quality = scratchCard.getQuantity();
				if (deno == NumberUtils.VND20000) {
					setNumber20k(quality);
					setDetail20k(scratchCard.getScDesription());
				}
				if (deno == NumberUtils.VND50000) {
					setNumber50k(quality);
					setDetail50k(scratchCard.getScDesription());
				}
				if (deno == NumberUtils.VND100000) {
					setNumber100k(quality);
					setDetail100k(scratchCard.getScDesription());
				}
				if (deno == NumberUtils.VND200000) {
					setNumber200k(quality);
					setDetail200k(scratchCard.getScDesription());
				}
				if (deno == NumberUtils.VND500000) {
					setNumber500k(quality);
					setDetail500k(scratchCard.getScDesription());
				}
			}
			if (fixedDepositCasa.getCustomerType() == 1) {
				setTshirtGift(fixedDepositCasa.getBagGift());
				setTrayGift(fixedDepositCasa.getTrayGift());
				setBgiftReceived(fixedDepositCasa.getBgiftReceived());
				setTgiftReceived(fixedDepositCasa.getTgiftReceived());
			}
			setBtnSaveVisible(true);
			break;
		}
	}

	public void updateInfoToPrint() throws MalformedURLException, JRException,
			FileNotFoundException {
		switch (nav_flag) {
		case 0:
			break;
		case 1:
			// ////////////////////////////////////////////////////////////
			int total_sc = number00k + number20k + number50k + number100k
					+ number200k + number500k;
			int total_sc_full = fixedDeposits.getScCard()
					+ getTotalScradAvailable();
			fixedDeposits.setBgiftReceived(getBgiftReceived());
			fixedDeposits.setTgiftReceived(getTgiftReceived());
			fixedDeposits.setVoucherGiftMore(getVoucherGiftMore());

			int bagReceived = fixedDeposits.getBgiftReceived();
			int trayReceived = fixedDeposits.getTgiftReceived();
			int vcherReceived = fixedDeposits.getVoucherGiftMore();

			bagReceived = bagReceived * 5;
			trayReceived = trayReceived * 10;
			vcherReceived = vcherReceived * 30;
			int total_sc_received = bagReceived + trayReceived + vcherReceived;

			if (total_sc > fixedDeposits.getScCard()
					|| total_sc_received > total_sc_full) {
				setBtnSaveVisible(true);
				setBtnSaveVisible(true);
				FacesContext
						.getCurrentInstance()
						.addMessage(
								null,
								new FacesMessage(
										FacesMessage.SEVERITY_WARN,
										"Vượt quá số lượng áo thun, khay mứt hoặc thẻ cào cho phép ",
										"Vui lòng nhập lại"));
			} else {

				if (total_sc == fixedDeposits.getScCard()) {
					try {
						fixedDeposits.setScCardNotGet(fixedDeposits.getScCard()
								- total_sc_received);
						mdbServices.deleteScratchCardByTransRef(fixedDeposits
								.getSavingbookNo());
						if (number20k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(fixedDeposits
									.getSavingbookNo());
							scratchCard.setCreatedBy(fixedDeposits
									.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail20k);
							scratchCard.setCustomerRef(fixedDeposits
									.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(20000);
							scratchCard.setQuantity(number20k);
							mdbServices.addScratchCard(scratchCard);
						}
						if (number50k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(fixedDeposits
									.getSavingbookNo());
							scratchCard.setCreatedBy(fixedDeposits
									.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail50k);
							scratchCard.setCustomerRef(fixedDeposits
									.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(50000);
							scratchCard.setQuantity(number50k);
							mdbServices.addScratchCard(scratchCard);

						}
						if (number100k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(fixedDeposits
									.getSavingbookNo());
							scratchCard.setCreatedBy(fixedDeposits
									.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail100k);
							scratchCard.setCustomerRef(fixedDeposits
									.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(100000);
							scratchCard.setQuantity(number100k);
							mdbServices.addScratchCard(scratchCard);

						}
						if (number200k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(fixedDeposits
									.getSavingbookNo());
							scratchCard.setCreatedBy(fixedDeposits
									.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail200k);
							scratchCard.setCustomerRef(fixedDeposits
									.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(200000);
							scratchCard.setQuantity(number200k);
							mdbServices.addScratchCard(scratchCard);

						}
						if (number500k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(fixedDeposits
									.getSavingbookNo());
							scratchCard.setCreatedBy(fixedDeposits
									.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail500k);
							scratchCard.setCustomerRef(fixedDeposits
									.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(500000);
							scratchCard.setQuantity(number500k);
							mdbServices.addScratchCard(scratchCard);
						}
						if (number00k > 0) {
							fixedDeposits.setCheckGetThankSC(number00k);
						}
						// /////////////////////////
						String fileName = fixedDeposits.getSavingbookNo()
								+ "-Updated" + ".pdf";
						Map<String, Object> data = new HashMap<String, Object>();
						data.put("BranchID", fixedDeposits.getBranchCode());
						data.put("CustomerID", fixedDeposits.getCustomerId());
						data.put("CustomerName",
								fixedDeposits.getCustomerName());
						data.put("SavingBookNo",
								fixedDeposits.getSavingbookNo());
						data.put("FDAmount", NumberUtils.format(fixedDeposits
								.getAmount().toString(), "###,###,###,###"));
						data.put("FDTerm", fixedDeposits.getTerm());
						data.put("FDInterest", Double.toString(fixedDeposits
								.getInterestRate()));
						data.put("TotalSCard", fixedDeposits.getScCard());
						data.put("TotalLDR", fixedDeposits.getLuckyDraw());

						data.put("BranchName", mdbServices
								.getCompanyNameByCode(fixedDeposits
										.getBranchCode()));
						data.put(
								"LuckyDrawCodes",
								mdbServices.getAllLuckyDrawCodeP(
										fixedDeposits.getSavingbookNo(), 0));

						List<ScratchCard> scratchCards = mdbServices
								.getScratchCardByRef(fixedDeposits
										.getSavingbookNo());
						double totalSCAmount = 0;
						for (ScratchCard scratchCard : scratchCards) {
							if (scratchCard.getScDenomination() == 20000) {
								data.put("Card20k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 20000;
							}
							if (scratchCard.getScDenomination() == 50000) {
								data.put("Card50k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 50000;
							}
							if (scratchCard.getScDenomination() == 100000) {
								data.put("Card100k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 100000;
							}
							if (scratchCard.getScDenomination() == 200000) {
								data.put("Card200k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 200000;
							}
							if (scratchCard.getScDenomination() == 500000) {
								data.put("Card500k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 500000;
							}

						}
						data.put("TotalSCAmount", NumberUtils.format(
								totalSCAmount, "###,###,###,###"));
						data.put(
								"ImagesPath",
								FacesContextUtils
										.getResourcePath("/WEB-INF/classes/mdb/com/vn/web/reports/MDB.jpg"));

						FixedDeposits deposits = mdbServices
								.findFixedDepositsByCode(fixedDeposits
										.getSavingbookNo());
						if (fixedDeposits.getInterestRate() == 7.5) {
							fixedDeposits
									.setScCardNotGet(0 - total_sc_received);
						}
						if (fixedDeposits.getCustomerType() == 1) {
							fixedDeposits.setId(deposits.getId());
							data.put("ThanksCard",
									fixedDeposits.getCheckGetThankSC());
							fixedDeposits.setScCardAmt(totalSCAmount);
							data.put("TshirtGift",
									fixedDeposits.getBgiftReceived());
							data.put("TrayGift",
									fixedDeposits.getTgiftReceived());

							mdbServices.updateFixedDeposits(fixedDeposits);

							JasperReport jasperReport = JasperCompileManager
									.compileReport(FacesContextUtils
											.getResourcePath("/WEB-INF/classes/mdb/com/vn/web/reports/FDReport.jrxml"));

							JasperPrint jasperPrint = JasperFillManager
									.fillReport(jasperReport, data,
											new JREmptyDataSource());

							JasperExportManager.exportReportToPdfFile(
									jasperPrint, fileName);
						}
						if (fixedDeposits.getCustomerType() == 2) {
							double temPSCAmount = totalSCAmount
									+ getTotalAmountAvailable();

							int voucherGift = (int) (temPSCAmount / 100000);
							fixedDeposits.setId(deposits.getId());
							fixedDeposits.setVoucherGift(voucherGift);
							fixedDeposits.setScCardAmt(totalSCAmount);
							fixedDeposits.setScCardAmtNot(totalSCAmount
									- (voucherGift * 100000));

							data.put("ThanksCard",
									fixedDeposits.getCheckGetThankSC());
							mdbServices.updateFixedDeposits(fixedDeposits);
							data.put("VoucherGift", voucherGift);
							data.put("VoucherGiftMore",
									fixedDeposits.getVoucherGiftMore());
							JasperReport jasperReport = JasperCompileManager
									.compileReport(FacesContextUtils
											.getResourcePath("/WEB-INF/classes/mdb/com/vn/web/reports/FDSMEReport.jrxml"));

							JasperPrint jasperPrint = JasperFillManager
									.fillReport(jasperReport, data,
											new JREmptyDataSource());

							JasperExportManager.exportReportToPdfFile(
									jasperPrint, fileName);
						}
						File filetemps = new File(fileName);
						InputStream fis = new FileInputStream(filetemps);
						file = new DefaultStreamedContent(fis,
								"application/pdf", fileName);
						setBtnVisible(true);
						setBtnSaveVisible(false);
						FacesContext
								.getCurrentInstance()
								.addMessage(
										null,
										new FacesMessage(
												FacesMessage.SEVERITY_INFO,
												"Lưu thông tin thành công",
												"Bấm nút 'In phiếu thông tin' để in phiếu thông tin cho khách hàng"));

					} catch (Exception e) {
						setBtnSaveVisible(true);
						FacesContext.getCurrentInstance().addMessage(
								null,
								new FacesMessage(FacesMessage.SEVERITY_ERROR,
										"Lỗi xảy ra trong qua trình nhập liệu",
										"Vui lòng kiểm tra lại"));
						e.printStackTrace();
					}
				} else {
					setBtnSaveVisible(true);
					FacesContext.getCurrentInstance().addMessage(
							null,
							new FacesMessage(FacesMessage.SEVERITY_WARN,
									"Nhập chưa đầy đủ số lượng thẻ cào",
									"Vui lòng kiểm tra lại"));

				}

			}
			// ////////////////////////////////////////////////////////////
			break;
		case 2:
			// /////////////////////////////////////////////////////////////////
			int total_sc_CS = number00k + number20k + number50k + number100k
					+ number200k + number500k;
			int total_sc_full_CS = casa.getScCard() + getTotalScradAvailable();
			casa.setBgiftReceived(getBgiftReceived());
			casa.setTgiftReceived(getTgiftReceived());
			int bagReceivedCS = casa.getBgiftReceived();
			int trayReceivedCS = casa.getTgiftReceived();

			bagReceivedCS = bagReceivedCS * 5;
			trayReceivedCS = trayReceivedCS * 10;
			int total_sc_received_CS = bagReceivedCS + trayReceivedCS;

			if (total_sc_CS > casa.getScCard()
					|| total_sc_received_CS > total_sc_full_CS) {
				setBtnSaveVisible(true);
				setBtnVisible(false);
				FacesContext
						.getCurrentInstance()
						.addMessage(
								null,
								new FacesMessage(
										FacesMessage.SEVERITY_WARN,
										"Vượt quá số lượng áo thun, khay mứt và thẻ cào cho phép ",
										"Vui lòng nhập lại"));
			} else {

				if (total_sc_CS == casa.getScCard()) {
					try {
						casa.setScCardNotGet(casa.getScCard()
								- total_sc_received_CS);
						// mdbServices.addCasa(casa);
						mdbServices.deleteScratchCardByTransRef(casa
								.getAccountLocked());
						if (number20k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(casa.getAccountLocked());
							scratchCard.setCreatedBy(casa.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail20k);
							scratchCard.setCustomerRef(casa.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(20000);
							scratchCard.setQuantity(number20k);
							mdbServices.addScratchCard(scratchCard);
						}
						if (number50k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(casa.getAccountLocked());
							scratchCard.setCreatedBy(casa.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail50k);
							scratchCard.setCustomerRef(casa.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(50000);
							scratchCard.setQuantity(number50k);
							mdbServices.addScratchCard(scratchCard);

						}
						if (number100k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(casa.getAccountLocked());
							scratchCard.setCreatedBy(casa.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail100k);
							scratchCard.setCustomerRef(casa.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(100000);
							scratchCard.setQuantity(number100k);
							mdbServices.addScratchCard(scratchCard);

						}
						if (number200k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(casa.getAccountLocked());
							scratchCard.setCreatedBy(casa.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail200k);
							scratchCard.setCustomerRef(casa.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(200000);
							scratchCard.setQuantity(number200k);
							mdbServices.addScratchCard(scratchCard);

						}
						if (number500k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(casa.getAccountLocked());
							scratchCard.setCreatedBy(casa.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail500k);
							scratchCard.setCustomerRef(casa.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(500000);
							scratchCard.setQuantity(number500k);
							mdbServices.addScratchCard(scratchCard);

						}
						if (number00k > 0) {
							casa.setCheckGetThankSC(number00k);
						}
						// /////////////////////////
						String fileName = casa.getAccountLocked() + "-Updated"
								+ ".pdf";
						Map<String, Object> data = new HashMap<String, Object>();

						data.put("BranchID", casa.getBranchCode());
						data.put("CustomerID", casa.getCustomerId());
						data.put("CustomerName", casa.getCustomerName());
						data.put("SavingBookNo", casa.getAccountLocked());

						data.put("CasaAmount", NumberUtils.format(
								casa.getWbBalances(), "###,###,###,###"));
						data.put("CasaTerm", casa.getTermLocked());

						data.put("TotalSCard", casa.getScCard());
						data.put("TotalLDR", casa.getLuckyDraw());

						data.put("BranchName", mdbServices
								.getCompanyNameByCode(casa.getBranchCode()));
						data.put(
								"LuckyDrawCodes",
								mdbServices.getAllLuckyDrawCodeP(
										casa.getAccountLocked(), 0));
						data.put("DateExpired", DateUtils.format(
								casa.getEndDateLocked(), "dd/MM/yyyy"));

						List<ScratchCard> scratchCards = mdbServices
								.getScratchCardByRef(casa.getAccountLocked());

						double totalSCAmount = 0;
						for (ScratchCard scratchCard : scratchCards) {
							if (scratchCard.getScDenomination() == 20000) {
								data.put("Card20k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 20000;
							}
							if (scratchCard.getScDenomination() == 50000) {
								data.put("Card50k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 50000;
							}
							if (scratchCard.getScDenomination() == 100000) {
								data.put("Card100k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 100000;
							}
							if (scratchCard.getScDenomination() == 200000) {
								data.put("Card200k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 200000;
							}
							if (scratchCard.getScDenomination() == 500000) {
								data.put("Card500k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 500000;
							}
						}
						data.put("TotalSCAmount", NumberUtils.format(
								totalSCAmount, "###,###,###,###"));
						data.put(
								"ImagesPath",
								FacesContextUtils
										.getResourcePath("/WEB-INF/classes/mdb/com/vn/web/reports/MDB.jpg"));

						Casa casa2update = mdbServices.findCasaByCode(casa
								.getAccountLocked());

						if (casa.getCustomerType() == 1) {
							casa.setId(casa2update.getId());
							data.put("ThanksCard", casa.getCheckGetThankSC());
							data.put("TshirtGift", casa.getBgiftReceived());
							data.put("TrayGift", casa.getTgiftReceived());
							casa.setScCardAmt(totalSCAmount);
							mdbServices.updateCasa(casa);

							JasperReport jasperReport = JasperCompileManager
									.compileReport(FacesContextUtils
											.getResourcePath("/WEB-INF/classes/mdb/com/vn/web/reports/CASAReport.jrxml"));

							JasperPrint jasperPrint = JasperFillManager
									.fillReport(jasperReport, data,
											new JREmptyDataSource());

							JasperExportManager.exportReportToPdfFile(
									jasperPrint, fileName);
						}
						File filetemps = new File(fileName);
						InputStream fis = new FileInputStream(filetemps);
						file = new DefaultStreamedContent(fis,
								"application/pdf", fileName);
						filetemps = new File(filetemps.getCanonicalPath());
						filetemps.delete();
						setBtnVisible(true);
						setBtnSaveVisible(false);
						FacesContext
								.getCurrentInstance()
								.addMessage(
										null,
										new FacesMessage(
												FacesMessage.SEVERITY_INFO,
												"Lưu thông tin thành công",
												"Bấm nút 'In phiếu thông tin' để in phiếu thông tin cho khách hàng"));

					} catch (Exception e) {
						setBtnSaveVisible(true);
						FacesContext.getCurrentInstance().addMessage(
								null,
								new FacesMessage(FacesMessage.SEVERITY_ERROR,
										"Lỗi xảy ra trong qua trình thao tác",
										"Vui lòng kiểm tra lại"));
						e.printStackTrace();
					}
				} else {
					setBtnSaveVisible(true);
					FacesContext.getCurrentInstance().addMessage(
							null,
							new FacesMessage(FacesMessage.SEVERITY_WARN,
									"Nhập chưa đầy đủ số lượng thẻ cào",
									"Vui lòng kiểm tra lại"));

				}

			}
			// /////////////////////////////////////////////////////////////////
			break;
		case 3:
			// ///////////////////////////////////////////////////////////////////
			int total_scFDCS = number00k + number20k + number50k + number100k
					+ number200k + number500k;
			int total_sc_fullFDCS = fixedDepositCasa.getScCard()
					+ getTotalScradAvailable();
			fixedDepositCasa.setBgiftReceived(getBgiftReceived());
			fixedDepositCasa.setTgiftReceived(getTgiftReceived());

			int bagReceivedFDCS = fixedDepositCasa.getBgiftReceived();
			int trayReceivedFDCS = fixedDepositCasa.getTgiftReceived();

			bagReceivedFDCS = bagReceivedFDCS * 5;
			trayReceivedFDCS = trayReceivedFDCS * 10;
			int total_sc_receivedFDCS = bagReceivedFDCS + trayReceivedFDCS;

			if (total_scFDCS > fixedDepositCasa.getScCard()
					|| total_sc_receivedFDCS > total_sc_fullFDCS) {
				setBtnSaveVisible(true);
				setBtnVisible(false);
				FacesContext
						.getCurrentInstance()
						.addMessage(
								null,
								new FacesMessage(
										FacesMessage.SEVERITY_WARN,
										"Vượt quá số lượng áo thun, khay mứt và thẻ cào cho phép ",
										"Vui lòng nhập lại"));
			} else {

				if (total_scFDCS == fixedDepositCasa.getScCard()) {
					try {
						fixedDepositCasa.setScCardNotGet(fixedDepositCasa
								.getScCard() - total_sc_receivedFDCS);
						mdbServices
								.deleteScratchCardByTransRef(fixedDepositCasa
										.getSavingbookNo());
						if (number20k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(fixedDepositCasa
									.getSavingbookNo());
							scratchCard.setTransRef1(fixedDepositCasa
									.getAccountLocked());
							scratchCard.setCreatedBy(fixedDepositCasa
									.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail20k);
							scratchCard.setCustomerRef(fixedDepositCasa
									.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(20000);
							scratchCard.setQuantity(number20k);
							mdbServices.addScratchCard(scratchCard);
						}
						if (number50k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(fixedDepositCasa
									.getSavingbookNo());
							scratchCard.setTransRef1(fixedDepositCasa
									.getAccountLocked());
							scratchCard.setCreatedBy(fixedDepositCasa
									.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail50k);
							scratchCard.setCustomerRef(fixedDepositCasa
									.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(50000);
							scratchCard.setQuantity(number50k);
							mdbServices.addScratchCard(scratchCard);

						}
						if (number100k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(fixedDepositCasa
									.getSavingbookNo());
							scratchCard.setTransRef1(fixedDepositCasa
									.getAccountLocked());
							scratchCard.setCreatedBy(fixedDepositCasa
									.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail100k);
							scratchCard.setCustomerRef(fixedDepositCasa
									.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(100000);
							scratchCard.setQuantity(number100k);
							mdbServices.addScratchCard(scratchCard);

						}
						if (number200k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(fixedDepositCasa
									.getSavingbookNo());
							scratchCard.setTransRef1(fixedDepositCasa
									.getAccountLocked());
							scratchCard.setCreatedBy(fixedDepositCasa
									.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail200k);
							scratchCard.setCustomerRef(fixedDepositCasa
									.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(200000);
							scratchCard.setQuantity(number200k);
							mdbServices.addScratchCard(scratchCard);

						}
						if (number500k > 0) {
							ScratchCard scratchCard = new ScratchCard();
							scratchCard.setTransRef(fixedDepositCasa
									.getSavingbookNo());
							scratchCard.setTransRef1(fixedDepositCasa
									.getAccountLocked());
							scratchCard.setCreatedBy(fixedDepositCasa
									.getCreatedBy());
							scratchCard.setDateCreated(new Date());
							scratchCard.setScDesription(detail500k);
							scratchCard.setCustomerRef(fixedDepositCasa
									.getCustomerId());
							scratchCard.setStatus(1);
							scratchCard.setScDenomination(500000);
							scratchCard.setQuantity(number500k);
							mdbServices.addScratchCard(scratchCard);

						}
						if (number00k > 0) {
							fixedDepositCasa.setCheckGetThankSC(number00k);
						}
						String fileName = fixedDepositCasa.getSavingbookNo()
								+ "-" + fixedDepositCasa.getAccountLocked()
								+ "-Updated" + ".pdf";
						Map<String, Object> data = new HashMap<String, Object>();

						data.put("BranchID", fixedDepositCasa.getBranchCode());
						data.put("CustomerID", fixedDepositCasa.getCustomerId());
						data.put("CustomerName",
								fixedDepositCasa.getCustomerName());
						data.put("SavingBookNo",
								fixedDepositCasa.getSavingbookNo());
						data.put("FDAmount", NumberUtils.format(
								fixedDepositCasa.getFdAmount().toString(),
								"###,###,###,###"));
						data.put("FDTerm", fixedDepositCasa.getFdTerm());
						data.put("FDInterest", Double.toString(fixedDepositCasa
								.getInterestRate()));
						data.put("SavingAccountNo",
								fixedDepositCasa.getAccountLocked());
						data.put("CSAmount", NumberUtils.format(
								fixedDepositCasa.getWbBalances().toString(),
								"###,###,###,###"));
						data.put("TotalSCard", fixedDepositCasa.getScCard());
						data.put("TotalLDR",
								fixedDepositCasa.getLuckyDraw() / 2);

						data.put("BranchName", mdbServices
								.getCompanyNameByCode(fixedDepositCasa
										.getBranchCode()));
						data.put("LuckyDrawCodes", mdbServices
								.getAllLuckyDrawCodeP(
										fixedDepositCasa.getSavingbookNo(), 0));
						data.put("DateExpired", DateUtils.format(
								fixedDepositCasa.getEndDateLocked(),
								"dd/MM/yyyy"));
						List<ScratchCard> scratchCards = mdbServices
								.getScratchCardByRef(fixedDepositCasa
										.getSavingbookNo());
						double totalSCAmount = 0;
						for (ScratchCard scratchCard : scratchCards) {
							if (scratchCard.getScDenomination() == 20000) {
								data.put("Card20k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 20000;
							}
							if (scratchCard.getScDenomination() == 50000) {
								data.put("Card50k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 50000;
							}
							if (scratchCard.getScDenomination() == 100000) {
								data.put("Card100k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 100000;
							}
							if (scratchCard.getScDenomination() == 200000) {
								data.put("Card200k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 200000;
							}
							if (scratchCard.getScDenomination() == 500000) {
								data.put("Card500k", scratchCard.getQuantity());
								totalSCAmount += scratchCard.getQuantity() * 500000;
							}
						}
						data.put("TotalSCAmount", NumberUtils.format(
								totalSCAmount, "###,###,###,###"));
						data.put(
								"ImagesPath",
								FacesContextUtils
										.getResourcePath("/WEB-INF/classes/mdb/com/vn/web/reports/MDB.jpg"));

						FixedDepositCasa depositsCasa = mdbServices
								.findFixedDepositCasaByCode(
										fixedDepositCasa.getSavingbookNo(),
										fixedDepositCasa.getAccountLocked());

						if (fixedDepositCasa.getCustomerType() == 1) {
							// update FD to DB
							fixedDepositCasa.setId(depositsCasa.getId());
							data.put("ThanksCard",
									fixedDepositCasa.getCheckGetThankSC());
							data.put("TshirtGift",
									fixedDepositCasa.getBgiftReceived());
							data.put("TrayGift",
									fixedDepositCasa.getTgiftReceived());
							fixedDepositCasa.setScCardAmt(totalSCAmount);
							mdbServices
									.updateFixedDepositCasa(fixedDepositCasa);

							JasperReport jasperReport = JasperCompileManager
									.compileReport(FacesContextUtils
											.getResourcePath("/WEB-INF/classes/mdb/com/vn/web/reports/FDCASAReport.jrxml"));

							JasperPrint jasperPrint = JasperFillManager
									.fillReport(jasperReport, data,
											new JREmptyDataSource());

							JasperExportManager.exportReportToPdfFile(
									jasperPrint, fileName);
						}

						InputStream fis = new FileInputStream(
								new File(fileName));
						file = new DefaultStreamedContent(fis,
								"application/pdf", fileName);
						setBtnVisible(true);
						setBtnSaveVisible(false);
						FacesContext
								.getCurrentInstance()
								.addMessage(
										null,
										new FacesMessage(
												FacesMessage.SEVERITY_INFO,
												"Lưu thông tin thành công",
												"Bấm nút 'In phiếu thông tin' để in phiếu thông tin cho khách hàng"));

					} catch (Exception e) {
						setBtnSaveVisible(true);
						setBtnVisible(false);
						FacesContext.getCurrentInstance().addMessage(
								null,
								new FacesMessage(FacesMessage.SEVERITY_ERROR,
										"Lỗi xảy ra trong qua trình nhập liệu",
										"Vui lòng kiểm tra lại"));
						e.printStackTrace();
					}
				} else {
					setBtnSaveVisible(true);
					setBtnVisible(false);
					FacesContext.getCurrentInstance().addMessage(
							null,
							new FacesMessage(FacesMessage.SEVERITY_WARN,
									"Nhập chưa đầy đủ số lượng thẻ cào",
									"Vui lòng kiểm tra lại"));
				}
			}
			// ///////////////////////////////////////////////////////////////////
			break;
		}
	}

	public void downloadPrevented() {
		// setBtnVisible(true);
		file = null;
	}

	/**
	 * @return the savingBookNo
	 */
	public String getSavingBookNo() {
		return savingBookNo;
	}

	/**
	 * @param savingBookNo
	 *            the savingBookNo to set
	 */
	public void setSavingBookNo(String savingBookNo) {
		this.savingBookNo = savingBookNo;
	}

	/**
	 * @return the number20k
	 */
	public int getNumber20k() {
		return number20k;
	}

	/**
	 * @param number20k
	 *            the number20k to set
	 */
	public void setNumber20k(int number20k) {
		this.number20k = number20k;
	}

	/**
	 * @return the number50k
	 */
	public int getNumber50k() {
		return number50k;
	}

	/**
	 * @param number50k
	 *            the number50k to set
	 */
	public void setNumber50k(int number50k) {
		this.number50k = number50k;
	}

	/**
	 * @return the number100k
	 */
	public int getNumber100k() {
		return number100k;
	}

	/**
	 * @param number100k
	 *            the number100k to set
	 */
	public void setNumber100k(int number100k) {
		this.number100k = number100k;
	}

	/**
	 * @return the number200k
	 */
	public int getNumber200k() {
		return number200k;
	}

	/**
	 * @param number200k
	 *            the number200k to set
	 */
	public void setNumber200k(int number200k) {
		this.number200k = number200k;
	}

	/**
	 * @return the number500k
	 */
	public int getNumber500k() {
		return number500k;
	}

	/**
	 * @param number500k
	 *            the number500k to set
	 */
	public void setNumber500k(int number500k) {
		this.number500k = number500k;
	}

	/**
	 * @return the detail20k
	 */
	public String getDetail20k() {
		return detail20k;
	}

	/**
	 * @param detail20k
	 *            the detail20k to set
	 */
	public void setDetail20k(String detail20k) {
		this.detail20k = detail20k;
	}

	/**
	 * @return the detail50k
	 */
	public String getDetail50k() {
		return detail50k;
	}

	/**
	 * @param detail50k
	 *            the detail50k to set
	 */
	public void setDetail50k(String detail50k) {
		this.detail50k = detail50k;
	}

	/**
	 * @return the detail100k
	 */
	public String getDetail100k() {
		return detail100k;
	}

	/**
	 * @param detail100k
	 *            the detail100k to set
	 */
	public void setDetail100k(String detail100k) {
		this.detail100k = detail100k;
	}

	/**
	 * @return the detail200k
	 */
	public String getDetail200k() {
		return detail200k;
	}

	/**
	 * @param detail200k
	 *            the detail200k to set
	 */
	public void setDetail200k(String detail200k) {
		this.detail200k = detail200k;
	}

	/**
	 * @return the detail500k
	 */
	public String getDetail500k() {
		return detail500k;
	}

	/**
	 * @param detail500k
	 *            the detail500k to set
	 */
	public void setDetail500k(String detail500k) {
		this.detail500k = detail500k;
	}

	/**
	 * @return the customerName
	 */
	public String getCustomerName() {
		return customerName;
	}

	/**
	 * @param customerName
	 *            the customerName to set
	 */
	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	/**
	 * @return the customerId
	 */
	public String getCustomerId() {
		return customerId;
	}

	/**
	 * @param customerId
	 *            the customerId to set
	 */
	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}

	/**
	 * @return the branchCode
	 */
	public String getBranchCode() {
		return branchCode;
	}

	/**
	 * @param branchCode
	 *            the branchCode to set
	 */
	public void setBranchCode(String branchCode) {
		this.branchCode = branchCode;
	}

	/**
	 * @return the programJoined
	 */
	public String getProgramJoined() {
		return programJoined;
	}

	/**
	 * @param programJoined
	 *            the programJoined to set
	 */
	public void setProgramJoined(String programJoined) {
		this.programJoined = programJoined;
	}

	/**
	 * @return the luckyDraw
	 */
	public int getLuckyDraw() {
		return luckyDraw;
	}

	/**
	 * @param luckyDraw
	 *            the luckyDraw to set
	 */
	public void setLuckyDraw(int luckyDraw) {
		this.luckyDraw = luckyDraw;
	}

	/**
	 * @return the sc_Card
	 */
	public int getSc_Card() {
		return sc_Card;
	}

	/**
	 * @param sc_Card
	 *            the sc_Card to set
	 */
	public void setSc_Card(int sc_Card) {
		this.sc_Card = sc_Card;
	}

	/**
	 * @return the tshirtGift
	 */
	public int getTshirtGift() {
		return tshirtGift;
	}

	/**
	 * @param tshirtGift
	 *            the tshirtGift to set
	 */
	public void setTshirtGift(int tshirtGift) {
		this.tshirtGift = tshirtGift;
	}

	/**
	 * @return the trayGift
	 */
	public int getTrayGift() {
		return trayGift;
	}

	/**
	 * @param trayGift
	 *            the trayGift to set
	 */
	public void setTrayGift(int trayGift) {
		this.trayGift = trayGift;
	}

	/**
	 * @return the voucherGift
	 */
	public int getVoucherGift() {
		return voucherGift;
	}

	/**
	 * @param voucherGift
	 *            the voucherGift to set
	 */
	public void setVoucherGift(int voucherGift) {
		this.voucherGift = voucherGift;
	}

	/**
	 * @return the voucherGiftMore
	 */
	public int getVoucherGiftMore() {
		return voucherGiftMore;
	}

	/**
	 * @param voucherGiftMore
	 *            the voucherGiftMore to set
	 */
	public void setVoucherGiftMore(int voucherGiftMore) {
		this.voucherGiftMore = voucherGiftMore;
	}

	/**
	 * @return the bgiftReceived
	 */
	public int getBgiftReceived() {
		return bgiftReceived;
	}

	/**
	 * @param bgiftReceived
	 *            the bgiftReceived to set
	 */
	public void setBgiftReceived(int bgiftReceived) {
		this.bgiftReceived = bgiftReceived;
	}

	/**
	 * @return the tgiftReceived
	 */
	public int getTgiftReceived() {
		return tgiftReceived;
	}

	/**
	 * @param tgiftReceived
	 *            the tgiftReceived to set
	 */
	public void setTgiftReceived(int tgiftReceived) {
		this.tgiftReceived = tgiftReceived;
	}

	/**
	 * @return the number00k
	 */
	public int getNumber00k() {
		return number00k;
	}

	/**
	 * @param number00k
	 *            the number00k to set
	 */
	public void setNumber00k(int number00k) {
		this.number00k = number00k;
	}

	/**
	 * @return the file
	 */
	public StreamedContent getFile() {
		return file;
	}

	/**
	 * @return the btnVisible
	 */
	public boolean isBtnVisible() {
		return btnVisible;
	}

	/**
	 * @param btnVisible
	 *            the btnVisible to set
	 */
	public void setBtnVisible(boolean btnVisible) {
		this.btnVisible = btnVisible;
	}

	/**
	 * @return the btnSaveVisible
	 */
	public boolean isBtnSaveVisible() {
		return btnSaveVisible;
	}

	/**
	 * @param btnSaveVisible
	 *            the btnSaveVisible to set
	 */
	public void setBtnSaveVisible(boolean btnSaveVisible) {
		this.btnSaveVisible = btnSaveVisible;
	}

	/**
	 * @return the totalScradAvailable
	 */
	public int getTotalScradAvailable() {
		return totalScradAvailable;
	}

	/**
	 * @param totalScradAvailable
	 *            the totalScradAvailable to set
	 */
	public void setTotalScradAvailable(int totalScradAvailable) {
		this.totalScradAvailable = totalScradAvailable;
	}

	/**
	 * @return the totalAmountAvailable
	 */
	public double getTotalAmountAvailable() {
		return totalAmountAvailable;
	}

	/**
	 * @param totalAmountAvailable
	 *            the totalAmountAvailable to set
	 */
	public void setTotalAmountAvailable(double totalAmountAvailable) {
		this.totalAmountAvailable = totalAmountAvailable;
	}

}
